/* 
  1.该文件，用于统一管理项目中所有的ajax请求。
  2.服务器上每一个接口，在该文件中都对应一个请求函数。
  3.该文件中，所有的函数命名规范都是：reqXxxx。
*/
import ajax from "./ajax";

import ajaxCart from "./ajaxCart";

// 注册页:获取验证码 完成注册
export const reqVerifyCodeByPhone = (phone) =>
  ajaxCart.get(`/user/passport/sendCode/${phone}`);
export const reqRegister = (params) =>
  ajaxCart.post("/user/passport/register", params);
// 登录页:登录
export const reqLogin = (params) =>
  ajaxCart.post("/user/passport/login", params);
// 个人中心:个人信息 退出登录
export const reqUserInfo = () =>
  ajaxCart.get("/user/passport/auth/getUserInfo");
export const reqLogOut = () => ajaxCart.get("/user/passport/logout");

// 默认关键字和热门关键字
export function reqHotSearchList() {
  return ajax({
    url: "/xhr/search/init.json",
    method: "post",
  });
}

// 实时关键字列表
export function reqLiveSearch(keywords) {
  return ajax({
    url: "/xhr/search/searchAutoComplete.json",
    method: "post",
    data: `keywordPrefix=${keywords}`,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    },
  });
}

// 搜索
export function reqSearchResult(info) {
  return ajax({
    // 传输进来对象，将需要的数据拼接到url
    url: `/xhr/search/search.json?__timestamp=1630133434953&needPopWindow=true&searchWordSource=7&stillSearch=false&_stat_search=autoComplete&itemId=0&size=40&upperPrice=${info.upperPrice}&floorPrice=${info.floorPrice}&matchType=0&categoryId=0&descSorted=${info.descSorted}&sortType=${info.sortType}&keyword=${info.keyword}`,
    method: "get",
  });
}

//首页推荐请求
export function reqHomeRecommend() {
  return ajax({
    url: "/xhr/index.json?__timestamp=1630131808529",
    method: "get",
    // data: `keywordPrefix=${searchKeywords}`,
    // headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
  });
}

//首页某个频道请求
export function reqHomeOther(id) {
  return ajax({
    url: "/item/list.json?__timestamp=1630136511866&categoryId=" + id,
    method: "get",
    // data: `keywordPrefix=${searchKeywords}`,
    // headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
  });
}

//值得买轮播数据
export function reqWorthSwiper() {
  return ajax({
    url: "/topic/v1/know/navWap.json",
    method: "get",
  });
}

//值得买瀑布流的分页数据
export function reqWorthLook() {
  return ajax({
    url: "/topic/v1/find/recAuto.json?page=2&size=2",
    method: "get",
  });
}

// 为你推荐和分类列表数据
export function reqCateList() {
  return ajax({
    url: "/item/cateList.json?__timestamp=1630131286110&categoryId=",
    method: "get",
  });
}
// 根据分类ID获取分类的列表：
export function getCateList(id) {
  return ajax.get(`/item/cateList.json?categoryId=${id}`);
}

// /获取某个分类下的商品列表：
export function getSubCateInfo(type, subId, cateId) {
  return ajax.get(`/item/list.json?categoryType=${type}&subCategoryId=${subId}&categoryId=${cateId}`);
}


//购物车
export const reqCartList = () => ajaxCart.get("/cart/cartList");

//请求勾选购物车
export const reqCheckSkuInCart = (skuId, isChecked) => ajaxCart.get(`/cart/checkCart/${skuId}/${isChecked}`)


export const reqAddOrUpdateCart = (skuId, skuNum) => ajaxCart.post(`/cart/addToCart/${skuId}/${skuNum}`)

export const reqCheckAllSkuInCart = (skuIdList, isChecked) => ajaxCart.post(`/cart/batchCheckCart/${isChecked}`, skuIdList)


//请求删除购物车中的商品
export const reqDeleteSkuInCart = (skuId) => ajaxCart.delete(`/cart/deleteCart/${skuId}`)
//请求批量删除购物车中的商品
export const reqBatchDeleteSkuInCart = (skuIdList) => ajaxCart.delete(`/cart/batchDeleteCart`,{data:skuIdList})

// 用于获取用户地址信息
// export const reqUserAddressList = ()=> ajax.get('/user/userAddress/auth/findUserAddressList')
// //用于获取交易详细信息
// export const reqTradeInfo = ()=> ajax.get('/order/auth/trade')
// //用于提交订单
// export const reqSubmitOrder =(tradeNo,params) => ajaxCart.post(`/order/auth/submitOrder?tradeNo=${tradeNo}`,params)
// //用于请求支付信息
// export const reqPayInfo = (orderId) => ajax.get(`/payment/weixin/createNative/${orderId}`)
// //用于查询某订单的支付状态
// export const reqPayStatus = (orderId) => ajax.get(`/payment/weixin/queryPayStatus/${orderId}`)

